package com.springcloudemo.ms;

import com.springcloudemo.ms.facede.DemoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import static org.apache.dubbo.common.constants.ClusterRules.BROADCAST;

/**
 * Hello world!
 *
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableDubbo
public class DubboCacheApplication {

    public static void main(String[] args) {
        SpringApplication.run(DubboCacheApplication.class, args);
    }

    @RestController
    class EchoController {

        @Value("${server.port}")
        private String port;

        /**
         * 相当于给每个提供供方发送请求
         */
        @DubboReference(cache = "lru")
        private DemoService demoService;

        @RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
        public String echo(@PathVariable String string) {
            return demoService.sayHello(string+" port:") + port;
        }
    }
}